#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<array>
using namespace std;

class Solution {
public:
    int characterReplacement(string s, int k) {
        array<int,26> ABNums = {0};
        int counnt = 0;
        int left = 0;
        int right = 0;
        int res = 0;
        while(right<s.size()&&left<=right){
            ++ABNums[s[right]-'A'];
            counnt = max(counnt,ABNums[s[right]-'A']);
            ++right;
            if(right-left>counnt+k){
                --ABNums[s[left]-'A'];
                ++left;
                res = max(res,right-left);
            }          
            
        }
        res = max(res,right-left);
        return res;

    }
};